/**
 * url地址拼接
 *
 * @param args url
 * @returns The joined URL as a string
 */
export function joinUrls(...args: string[]): string {
  const cleaned = args
    .map(arg => arg.replace(/^\/+|\/+$/g, ''))
    .filter(Boolean)
  if (!cleaned.length)
    return '/'
  const firstOriginal = args[0] ?? ''
  return firstOriginal === '' || firstOriginal === '/'
    ? `/${cleaned.join('/')}`
    : cleaned.join('/')
}
